package com.aixx.springcloud.controller;

import com.aixx.springcloud.entities.CommonResult;
import com.aixx.springcloud.entities.Payment;
import com.aixx.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * web层
 * 控制器
 * @author shkstart
 * @create 2021-01-25 18:59
 */
@RestController//返回json数据到页面
@Slf4j
public class PayController {
    @Autowired
    private PaymentService service;

    @Value("${server.port}")
    private String serverPort;

     @PostMapping("/payment/create")
     public CommonResult create(@RequestBody Payment payment) {
       int i = service.create(payment);
       log.info("插入结果："+i);
       if (i>0) {
           return new CommonResult(200, "插入成功,端口号："+serverPort, i);
       }
           return new CommonResult(444,"失败,端口号："+serverPort);


   }
    @GetMapping("/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id")Long id){
       Payment result= service.getPaymentById(id);

       log.info("查询结果:"+result);
       if( result!=null){
           return new CommonResult(200, "查询成功,端口号"+serverPort, result);
         }
       return new CommonResult(444,"没有记录",null);
    }
}
